function request(config) {
  let header = {}
  let token = this.$db.getToken()
  if (token) {
    header['token'] = token
  }
  return new Promise((resolve, reject) => {
    uni.request({
      url: 'http://wuhu.njwhd.com/api/index/' + config.url,
      method: config.method || 'post',
      data: config.data || {},
      header,
      success(res) {
        if (res.data.code === 1) {
          resolve(res.data)
        } else {
          uni.showToast({
            title: res.data.msg,
            icon: 'none'
          })
          reject(res.data)
        }
      },
      fail(err) {
        reject(err)
      }
    })
  })
}
export default request
